﻿using HCApp.Core.Common.ViewModels;
using LinnerToolkit.Core.Commands;
using LinnerToolkit.Core.Navigation;
using LinnerToolkit.Core.Services;
using Prism.Commands;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Input;

namespace MainAppEntryPrismWpf.ViewModels
{
    public class Page1ViewModel : ViewModelBase
    {

        public ICommand SnakCommand { get; }

        public ICommand DialogCommand { get; }

        public ICommand LoadingCommand { get; }
        public ICommand ZTJKCommand { get; }

        public ICommand ConfirmCommand { get; }

        public ICommand SelectActionCommand { get; }
        public ICommand NavigateDeviceCommand { get; }
        public ICommand NavigateTrainCommand { get; }


        public ICommand HistoryInquireCommand { get; }


        public Page1ViewModel(IAppNavigationService navigationService, IDialogService dialogService) : base(navigationService)
        {
            SnakCommand = new LockDelegateCommand(async () =>
            {
                var result = await dialogService.SnackbarAsync("SNAC测试", "确定");
                if (result)
                {
                    NavigationService.NavigateAsync("Page1");
                }
            });



            HistoryInquireCommand = new LockDelegateCommand(async () =>
            {
              
                    NavigationService.NavigateAsync("HistoryReviewPage");
                
            });

            NavigateDeviceCommand = new LockDelegateCommand(async () =>
            {
                
                
               await NavigationService.NavigateAsync("YGXXManagePage");

            });




            NavigateTrainCommand = new LockDelegateCommand(async () =>
            {
                //string aStr = str;
                //await dialogService.AlertAsync("alert测试", "标题", aStr);
                //await NavigationService.NavigateAsync("SleepRepairPage", new AppNavigationParameters{
                //    { "Duration",60 },
                //    {"AutoWake",true },
                //    {"RepairType",RepairType.Sleep },
                //});

                await NavigationService.NavigateAsync("ChuKuManagePage");

            });



            DialogCommand = new LockDelegateCommand(async () =>
            {
                await dialogService.AlertAsync("alert测试", "标题", "acknownd");
            });

            LoadingCommand = new LockDelegateCommand(async () =>
            {
                //await dialogService.LoadingAsync("测试loading");

                //await Task.Delay(3000);

                //await dialogService.LoadingAsync("测试换文字");

                //await Task.Delay(3000);

                //await dialogService.DismissLoadingAsync();
                //      await NavigationService.NavigateAsync("YGSignInPage");
                await NavigationService.NavigateAsync("DailyRepository");

            });

            ZTJKCommand = new LockDelegateCommand(async () =>
            {
                //await dialogService.LoadingAsync("测试loading");

                //await Task.Delay(3000);

                //await dialogService.LoadingAsync("测试换文字");

                //await Task.Delay(3000);

                //await dialogService.DismissLoadingAsync();
                //      await NavigationService.NavigateAsync("YGSignInPage");
                //   await NavigationService.NavigateAsync("DailyRepository");


                Process exeYell = new Process();

                //   string Up2Path = System.IO.Directory.GetCurrentDirectory();
                string Up2Path = System.AppDomain.CurrentDomain.BaseDirectory;
                // ExternalHelpers.HitPath = Up2Path + @"\Hit\HitSystem.exe";

                // exeYell.StartInfo.FileName = Up2Path + @"\DSJK\DSJCGL.exe";
                exeYell.StartInfo.FileName = Up2Path + @"DSJK\DSJCGL.exe";
                exeYell.EnableRaisingEvents = true;
                App.Logger.Info(exeYell.StartInfo.FileName);
                // exeYell.Exited += exeYell_Exited;




                // ExternalHelpers.HitPath = Up2Path + @"\Hit\HitSystem.exe";

                //   exeYell.StartInfo.FileName = Up2Path + @"\ZXJK\ZXSBJC.exe";
              

               

                exeYell.Start();


            });

            ConfirmCommand = new LockDelegateCommand(async () =>
            {
                //var result = await dialogService.ConfirmAsync("问题描述", "问题标题");
                //if (result != null && result.Value)
                //{

                //}

                await NavigationService.NavigateAsync("RuKuManagePage");
            });

            SelectActionCommand = new LockDelegateCommand(async () =>
            {
                //int result = await dialogService.SelectActionAsync(new[] { "1", "2", "3", "4" }, "选择标题");
                //if (result >= 0)
                //{
                //    await dialogService.SnackbarAsync($"选择序号:{result}");
                //}

                await NavigationService.NavigateAsync("GGManagePage");
            });
        }

        public override void OnNavigatedFrom(AppNavigationParameters parameters)
        {
            base.OnNavigatedFrom(parameters);
        }

        public override void OnNavigatedTo(AppNavigationParameters parameters)
        {
            base.OnNavigatedTo(parameters);
        }
    }
}
